import { Toast } from 'vant'

export default function useCopy() {
  const copy = text => {
    try {
      const inputNode = document.createElement('input')
      inputNode.setAttribute('value', text)
      inputNode.setAttribute('readonly', true)
      document.body.appendChild(inputNode)
      inputNode.select()
      document.execCommand('Copy')
      document.body.removeChild(inputNode)
      Toast('复制成功')
    } catch (err) {
      Toast('复制失败，请重试')
    }
  }

  return {
    copy
  }
}
